# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
"""
FreeCell style stacks
"""

from .. import pilelib as stack
from .. import helpstrings as hs
from ..gamelib import state


class SequenceReserve(stack.ReserveStack):

    def cardsBuild(self, from_stack, cards):
        """
        cardsBuild(from_stack:obj, cards:seq) -> bool

        Check if pile can build with cards from from_stack. Addition pile
        may build with any _row_ seq while gap.

        :param object from_stack: sending pile
        :param sequence cards: cards from sending pile
        :return: pile accepts ``cards``?
        :rtype: boolean
        """
        return (not self.cards and from_stack._sequence(cards) and
                super(SequenceReserve).cardsBuild(from_stack, cards))


class NoFlipReserve(stack.OpenStack):

    def cardFlips(self):
        """
        cardFlips() -> bool

        :return: flip |top|?
        :rtype: boolean
        """
        return False


class FromTalonReserve(stack.FromTalonBuildMethod, stack.ReserveStack):
    pass


class FromWasteReserve(stack.FromWasteBuildMethod, stack.ReserveStack):
    pass


class Flipper_Row(stack.AC_RowStack):
    """
    AC_RowStack that cardFlips when Game.s.reserve of same index not cards.
    """

    def cardFlips(self):
        """
        cardFlips() -> bool

        Only when Game.s.reserve of same index not cards.

        :return: top card flips?
        :rtype: boolean
        """
        if not super(Flipper_Row, self).cardFlips():
            return False
        i = list(self.game.s['rows']).index(self)
        return not self.game.s['reserves'][i].cards


class Zerline_Reserve(stack.FromRowStackBuildMethod, stack.ReserveStack):
    pass